package service

import (
    "shoollove/model"
    "shoollove/pkg/db"
    "shoollove/pkg/tool"
)

// HelloAdd 添加
func HelloAdd(req model.HelloAdd) (resp any, err error) {
    dbBegin := db.Gorm
	//
	// 请求参数处理后添加到数据库
	// 赋值操作
    param := model.Hello{}
	err = dbBegin.Create(&param).Error
	if err != nil {
		return resp, err
	}
	return resp, nil
}

// HelloEdit 编辑
func HelloEdit(req model.HelloEdit) (resp any, err error) {
    session := db.Gorm

	param := model.Hello{}

	// 请求参数处理后添加到数据库
	// 赋值操作
    err = session.Updates(&param).Where("id = ?", req.Id).Error
    if err != nil {
        return resp, err
    }
    return resp, nil
}

// HelloDelete 删除
func HelloDelete(req model.HelloDelete) (resp any, err error) {
    session := db.Gorm


	if len(req.IdStr) > 0 {
	    err = session.Delete(&model.Hello{}).Where("id in ?", req.IdStr).Error
	}else{
	    err = session.Delete(&model.Hello{}).Where("id in ?", req.IdInt).Error
	}
	if err != nil {
		return resp, err
	}
    return resp, nil
}


// HelloGet 查询
func HelloGet(req model.HelloGet) (resp any, err error) {
    session := db.Gorm

	param := model.Hello{}

	// 赋值操作
    result, err := tool.Page(req.Page, req.Limit, session, &param)
    if err != nil {
        return resp, err
    }
    return result, nil
}


// HelloForm 查询
func HelloForm(req model.HelloForm) (resp any, err error) {
    session := db.Gorm

	param := model.Hello{}
	// 赋值操作
	err = session.Take(&param, req.Id).Error
	if err != nil {
		return resp, err
	}
    return resp, nil
}

